﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Patterns.DependencyInjection {

    public class SimpleDependencyResolver : IDependencyResolver {
        private readonly Dictionary<Type, object> _registry;

        public SimpleDependencyResolver() {
            _registry = new Dictionary<Type, object>();
        }

        public T Resolve<T>() {
            return (T)_registry[typeof(T)];
        }

        public void Register<T>(object obj) {
            if (obj is T == false) {
                throw new InvalidOperationException(
                    String.Format("The supplied instance does not implement {0}.",
                        typeof(T).FullName));
            }
            _registry[typeof(T)] = obj;
        }
    }
}
